home *** CD-ROM | disk | FTP | other *** search
/ A.C.E. 2 / ACE CD 2.iso / FILES / UTILS / COMICST1.DMS / in.adf / Source / mem.asm < prev    next >
Encoding:
Assembly Source File  |  1994-12-31  |  3.6 KB  |  109 lines

  1. ; (c) Frank Meijer, December 1994.
  2. ;
  3. ;--------------------------------------------------------------------
  4. ;   These routines are used to intercept calls to AllocMem().
  5. ;
  6. ;   Sample use:
  7. ;      realAllocMem = SetFunction( ExecBase, -198, myAllocMem );
  8. ;
  9. ;      This will cause "myAllocMem()" to be called instead of the
  10. ;      real AllocMem().
  11. ;
  12. ;      From there, CALLrealAllocMem() can be called to invoke the
  13. ;      real AllocMem() routine.
  14. ;
  15. ;   Notes:
  16. ;     - myAllocMem() must be defined by the caller.  It has the
  17. ;       same argument as AllocMem() but it is a 'C' function.
  18. ;         APTR myAllocMem( long size, long type );
  19. ;                  (D0)       (D0)       (D1)
  20. ;--------------------------------------------------------------------
  21. ;
  22.         xdef        _realAllocMem
  23.         xdef        _CALLmyAllocMem
  24.         xdef        _CALLrealAllocMem
  25. ;
  26.         xref        _myAllocMem
  27. ;
  28. ;---------------------------
  29.         section     0,bss
  30. MyExecBase:
  31.         dc.l        0                 ; Used to store exec.library base address
  32. _realAllocMem:
  33.         dc.l        0
  34. ;
  35. ;---------------------------
  36.         section     1,code
  37. _CALLmyAllocMem:
  38.         move.l      A6,MyExecBase     ; Store for use by CALLrealAllocMem
  39.         move.l      D1,-(sp)          ; Put parameters on stack
  40.         move.l      D0,-(sp)          ;  for call to C function
  41.         jsr         _myAllocMem
  42.         addq.l      #8,sp             ; Pop stack
  43.         rts
  44. ;
  45. ;---------------------------
  46.         section     1,code
  47. _CALLrealAllocMem:
  48.         move.l      4(sp),D0          ; get parameters from stack
  49.         move.l      8(sp),D1
  50.         move.l      A6,-(A7)          ; save A6
  51.         movea.l     MyExecBase,A6     ; set A6 to exec library base, see amiga.lib
  52.         move.l      _realAllocMem,A0
  53.         jsr         (A0)
  54.         movea.l     (A7)+,A6          ; restore A6
  55.         rts
  56. ;
  57. ;--------------------------------------------------------------------
  58. ;   These routines are used to intercept calls to FreeMem().
  59. ;
  60. ;   Sample use:
  61. ;      realFreeMem = SetFunction( ExecBase, -210, myFreeMem );
  62. ;
  63. ;      This will cause "myFreeMem()" to be called instead of the
  64. ;      real FreeMem().
  65. ;
  66. ;      From there, CALLrealFreeMem() can be called to invoke the
  67. ;      real FreeMem() routine.
  68. ;
  69. ;   Notes:
  70. ;     - myFreeMem() must be defined by the caller.  It has the
  71. ;       same argument as FreeMem() but it is a 'C' function.
  72. ;         void myFreeMem( APTR memaddress, long bytesize );
  73. ;                            (A1)            (D0)
  74. ;--------------------------------------------------------------------
  75. ;
  76.         xdef        _realFreeMem
  77.         xdef        _CALLmyFreeMem
  78.         xdef        _CALLrealFreeMem
  79. ;
  80.         xref        _myFreeMem
  81. ;
  82. ;---------------------------
  83.         section     0,bss
  84. _realFreeMem:
  85.         dc.l        0
  86. ;
  87. ;---------------------------
  88.         section     1,code
  89. _CALLmyFreeMem:
  90.         move.l      A6,MyExecBase     ; Store for use by CALLrealFreeMem
  91.         move.l      D0,-(sp)          ; Put parameters on stack
  92.         move.l      A1,-(sp)          ;  for call to C function
  93.         jsr         _myFreeMem
  94.         addq.l      #8,sp             ; Pop stack
  95.         rts
  96. ;
  97. ;---------------------------
  98.         section     1,code
  99. _CALLrealFreeMem:
  100.         move.l      4(sp),A1          ; get parameters from stack
  101.         move.l      8(sp),D0
  102.         move.l      A6,-(A7)          ; save A6
  103.         movea.l     MyExecBase,A6     ; set A6 to exec library base, see amiga.lib
  104.         move.l      _realFreeMem,A0
  105.         jsr         (A0)
  106.         movea.l     (A7)+,A6          ; restore A6
  107.         rts
  108. ;
  109.         end